package com.stylefeng.guns.modular.goods.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.goods.model.Sku;
import com.stylefeng.guns.modular.goods.service.ISkuService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-09-05 16:09:38
 */
@Controller
@RequestMapping("/sku")
public class SkuController extends BaseController {

    private String PREFIX = "/goods/sku/";

    @Autowired
    private ISkuService skuService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sku.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/sku_add")
    public String skuAdd() {
        return PREFIX + "sku_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/sku_update/{skuId}")
    public String skuUpdate(@PathVariable Long skuId, Model model) {
        Sku sku = skuService.selectById(skuId);
        model.addAttribute("item",sku);
        LogObjectHolder.me().set(sku);
        return PREFIX + "sku_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return skuService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Sku sku) {
        skuService.insert(sku);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long skuId) {
        skuService.deleteById(skuId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Sku sku) {
        skuService.updateById(sku);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{skuId}")
    @ResponseBody
    public Object detail(@PathVariable("skuId") Long skuId) {
        return skuService.selectById(skuId);
    }
}
